package com.yunxi.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.order.pojo.OrderActualSalesVO;
import com.yunxi.order.service.OrderActualSalesDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单实销表 前端控制器
 * </p>
 *
 * @author
 * @since 2019-07-18
 */
@RestController
@RequestMapping("/admin/orderactualsales")
@Api(tags = "pms:orderactualsales", description = "订单实销表接口")
public class OrderActualSalesController {
   private static final Logger logger = LoggerFactory.getLogger(OrderActualSalesController.class);

   @Autowired
   OrderActualSalesDubboService orderActualSalesDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(OrderActualSalesVO orderActualSalesVO, Integer pageNum, Integer pageSize , @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(orderActualSalesDubboService.findPageByVO(orderActualSalesVO, pageNum, pageSize , loginInfo));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult list(OrderActualSalesVO orderActualSalesVO) throws Exception {
      return ResponseUtil.ok(orderActualSalesDubboService.listByVo(orderActualSalesVO));
   }

   @GetMapping("/loadDetail")
   @ApiOperation(value = "根据零售单号读取单个详情")
   public ApiResult load(@RequestParam String orderCustomerNo, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(orderActualSalesDubboService.loadDetail(orderCustomerNo));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody OrderActualSalesVO orderActualSalesVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      orderActualSalesDubboService.saveOrUpdate(orderActualSalesVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<OrderActualSalesVO> orderActualSalesVOList) throws Exception {
      orderActualSalesDubboService.removeByListVo(orderActualSalesVOList);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/salesReported")
   @ApiOperation(value = "实销上报")
   public ApiResult salesReported(@RequestBody OrderActualSalesVO orderActualSalesVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      orderActualSalesDubboService.salesReported(orderActualSalesVO,loginInfo);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/testSalesReported")
   @ApiOperation(value = "实销上报")
   public ApiResult testSalesReported(@RequestBody OrderActualSalesVO orderActualSalesVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      orderActualSalesVO = orderActualSalesDubboService.loadDetail(orderActualSalesVO.getOrderCustomerNo());
      orderActualSalesDubboService.salesReported(orderActualSalesVO,loginInfo);
      return ResponseUtil.ok("success");
   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(orderActualSalesDubboService.findMapByList(params));
}*/
}
